from django.db import models
from django.contrib.auth.models import User
from tagging.fields import TagField
from tagging.models import Tag

from ceemtu.cetcore.models import FileEntry
import datetime

class MovieCategory(models.Model):
    """
    
    """
    text = models.CharField(max_length = 200)
    
MOVIE_FORMATS = (
    ('16:9', '16:9'),
    ('4:3', '4:3'),
    ('2.35:1', '2.35:1'),
    ('1.85:1', '1.85:1')
)
class Movie(models.Model):
    """
    
    """
    file_entry = models.ForeignKey(FileEntry, editable = False)
    title = models.CharField(max_length = 200, blank = True, null = True)
    release_year = models.CharField(max_length=100, blank = True, null = True)
    runningtime = models.IntegerField(null = True, blank = True)
    video_codec = models.CharField(max_length=100, blank = True, null = True)
    audio_codec = models.CharField(max_length=100, blank = True, null = True)
    movie_container = models.CharField(max_length=100, blank = True, null = True)
    width = models.IntegerField(blank = True, null = True)
    height = models.IntegerField(blank = True, null = True)
    resolution = models.CharField(max_length=100, blank = True, null = True) # 720p, 1080i, 1080p etc.
    movieformat = models.CharField(max_length=100, blank = True, null = True, choices = MOVIE_FORMATS) # 720p, 1080i, 1080p etc.

    date_added = models.DateTimeField(default=datetime.datetime.today(), editable = False)
    cover_image_hash = models.CharField(max_length = 128, null = True, blank = True, editable = False)
    categories = models.ManyToManyField(MovieCategory, null = True, blank = True)
    tags = models.ManyToManyField(Tag, null = True, blank = True)

    class Meta:
        ordering = ['-date_added', 'title']
        verbose_name = "Movie"
        verbose_name_plural = "Movies"

    def __unicode__(self):
        return self.title